package com.gurumades.jsonform.shared.dispatch.validators;

import java.util.HashMap;

import com.gurumades.jsonform.client.presenter.FormItemError;
import com.gurumades.jsonform.shared.dispatch.JsonHelper;

public class ValidatorHelper {

	private static JsonHelper jsonHelper;

	protected HashMap<String, FormItemError> errors = new HashMap<String, FormItemError>();
	public HashMap<String, FormItemError> errors() {
		return errors;
	}

	public void clearError() {
		errors.clear();
	}

	public boolean hasErrors() {
		return !errors.keySet().isEmpty();
	}

	public boolean hasErrors(boolean clearErrors) {
		boolean error = hasErrors();
		
		if (clearErrors) {
			clearError();
		}

		return error;
	}
	
	public void addError(String id, String message){
		errors.put(id, FormItemError.makeError(id, message));
	}

	public static void setJsonhelper(JsonHelper jsonHelper) {
		ValidatorHelper.jsonHelper = jsonHelper;
	}

	public static JsonHelper getJsonHelper() {
		return jsonHelper;
	}

}
